package com.example.foodtruckdemo.controller;

import com.example.foodtruckdemo.common.ApiResult;
import com.example.foodtruckdemo.controller.vo.FacilityTypeVo;
import com.example.foodtruckdemo.controller.vo.MobileFoodFacilityPermitPageByPositionReq;
import com.example.foodtruckdemo.controller.vo.MobileFoodFacilityPermitPageReq;
import com.example.foodtruckdemo.controller.vo.MobileFoodFacilityPermitPageVo;
import com.example.foodtruckdemo.enums.FacilityType;
import com.example.foodtruckdemo.service.MobileFoodFacilityPermitService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("mobileFoodFacilityPermit")
public class MobileFoodFacilityPermitController {
    @Resource
    private MobileFoodFacilityPermitService mobileFoodFacilityPermitService;

    /**
     * 分页查询餐车信息
     * @param req
     * @return
     */
    @PostMapping("page")
    public ApiResult<List<MobileFoodFacilityPermitPageVo>> page(@RequestBody @Valid MobileFoodFacilityPermitPageReq req){

        return mobileFoodFacilityPermitService.page(req);
    }

    /**
     * 查询参数类型
     * @return
     */
    @GetMapping("getFacilityTypes")
    public ApiResult<List<FacilityTypeVo>> getFacilityTypes(){
        List<FacilityTypeVo> types = Arrays.stream(FacilityType.values()).map(e -> new FacilityTypeVo(e.getCode())).collect(Collectors.toList());
        return ApiResult.success(types);
    }


    @PutMapping("updateGeohash")
    public void updateGeoHash(){
        mobileFoodFacilityPermitService.updateGeoHash();
    }

    /**
     * 查询附近餐车信息
     * @param req
     * @return
     */
    @PostMapping("getByPosition")
    public ApiResult<List<MobileFoodFacilityPermitPageVo>> getByPosition(@RequestBody @Valid MobileFoodFacilityPermitPageByPositionReq req){

        return mobileFoodFacilityPermitService.getByPosition(req);
    }
}
